/** 
*
* @author  jiwf 
* @date 创建时间：2016年9月4日 下午6:51:17 
* @version 1.0 
* @since  
*  
*/
package com.xbstar.websocket;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.xbstar.bean.MsgInfo;
import com.xbstar.bean.UserGroupRelation;
import com.xbstar.dao.MsgInfoRepository;
import com.xbstar.dao.UserGroupRelationRepository;
import com.xbstar.service.MsgInfoServiceImpl;
import com.xbstar.service.MsgService;
import com.xbstar.tools.SpringContextUtils;
@Deprecated
@Component
public class MsgControll {
	@Autowired
	MsgInfoRepository msgInfoRepository;
	@Autowired
	UserGroupRelationRepository userGroupRelationRepository;
	//private MsgInfoServiceImpl mis;
	public HashMap<Long, MsgInfo> dissolveMsg(MsgInfo msg) {
		//1.入库
		//2.查找所有应该收到这个消息的人
	    //3.发送
		msgInfoRepository.save(msg);
		//MsgInfoServiceImpl mis=SpringContextUtils.getContext().getBean(MsgInfoServiceImpl.class);
		//mis.save(msg);
		Long msgToUsers=msg.getToUserId();
		Short receiverType= msg.getReceiverType();
		HashMap<Long, MsgInfo> result=new HashMap<Long, MsgInfo>();
		
		if(receiverType==1){
			
			List<UserGroupRelation> list=userGroupRelationRepository.findByGroupId(msgToUsers);
			for (UserGroupRelation userGroupRelation : list) {
				result.put(userGroupRelation.getId(), msg);
			}
		}else{
			result.put(msgToUsers, msg);
		}
		return result;
	}

	
}
